package com.ztstkj.lzscale.app

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.jackiepenghe.serialportlibrary.DebugLevel
import com.jackiepenghe.serialportlibrary.MultipleSerialPortManager
import com.jackiepenghe.serialportlibrary.SerialPortManager
import com.sscl.baselibrary.utils.DebugUtil
import com.ztstkj.lzservices.mmkvs.MmkvUtil
import com.ztstkj.lzservices.serialports.SerialPortUtil

class MyApplication : Application() {
    companion object{
        //使用注解屏蔽可能发生内存泄露的警告
        //实际上,储存在这的context是applicationContext
        //不随Activity的生命周期变化,不会造成内存泄露
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context
    }
    override fun onCreate() {
        super.onCreate()
        context=applicationContext
        DebugUtil.setDebugFlag(true)
        MmkvUtil.instance.init(this)
        MultipleSerialPortManager.setDebugLevel(DebugLevel.OFF)
        SerialPortManager.setDebugLevel(DebugLevel.OFF)
        SerialPortUtil.openS4()
    }

    override fun onTerminate() {
        super.onTerminate()
        SerialPortUtil.close()
    }
//    private fun setNetCheckWorker(){
//        val oneTimeWorkRequest: OneTimeWorkRequest =
//            OneTimeWorkRequest.Builder(NetcheckWorker::class.java)
//                .setInitialDelay(15, TimeUnit.SECONDS)
//                .build()
//        WorkManager.getInstance(this).enqueue(oneTimeWorkRequest)
//    }
}